package com.larissa.quiz;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;

import java.util.UUID;

public class CreateQuestionActivity extends AppCompatActivity {
    private EditText questionText;
    private CheckBox questionAnswer;
    private Button btn_save;
    private QuizRepository repository;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_create_question);

        questionText=findViewById(R.id.question_title);
        questionAnswer=findViewById(R.id.ckb_true);
        btn_save=findViewById(R.id.btn_save_question);
        repository=QuizRepository.getInstance();

        btn_save.setOnClickListener(view -> addQuestion());
    }

    private void addQuestion(){
        String text=questionText.getText().toString();
        Boolean answer=false;
        if(questionAnswer.isChecked())
            answer=true;
        Question question=new Question(UUID.randomUUID(),text,answer);
        repository.addQuestion(question);
        finish();
    }


}